home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / nd92 / Z3 / 680x0.txt < prev   
Encoding:
Text File  |  1992-12-18  |  14.8 KB  |  288 lines

  1. (c)  Copyright 1992 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and is provided "as is" without warranty of any kind, either expressed
  4. or implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7. The 68030 and 68040 on the Zorro III Bus
  8.  
  9. by Michael Sinz
  10.  
  11.  
  12. The Zorro III bus presents several special design issues for systems
  13. with either a 68030 or 68040 CPU.  This article discusses those
  14. design issues and offers solutions to the potential problems that
  15. they present to those developing Zorro III devices, in particular,
  16. Zorro III devices that are not exclusively memory expansion devices.
  17.  
  18.  
  19. Background - 68030 and 68040 Caches
  20.  
  21. Both the 68030 and the 68040 have two caches; one for instructions
  22. and one for data.  The 68030's caches are 256-bytes long.  The
  23. 68040's caches are considerably larger: each is 4K long.  Both CPU's
  24. caches store memory in 16-byte blocks which are referred to as a
  25. cache line.  The CPU only keeps one address for each cache line.
  26. Each cache line is further broken up into long words called cache
  27. entries.  On the 68030, each cache entry is marked as either valid or
  28. invalid, telling the CPU which long words in the cache still contain
  29. valid data.  On the 68040, only an entire cache line can be marked as
  30. valid or invalid.
  31.  
  32. When the 68030 caches a memory address, it uses bits four through
  33. seven of the address as a hash value.  This value is an index that
  34. tells the 68030 which cache line to use for a specific address.  This
  35. means each memory address corresponds to only one cache line.  For
  36. example, if the 68030 tried to read a long word from 0x0FFFFF9F,
  37. since the 68030 index extends from bit four through seven, the index
  38. is 0x9, which corresponds to the tenth cache line.  This also means
  39. that many memory addresses correspond to the same cache line.  For
  40. example, the addresses 0x01FFFF9F, 0x02FFFF9F, 0x03FFFF9F, and
  41. 0x04FFFF9F all correspond to the same cache line.
  42.  
  43. The 68040 cache uses a similar indexing scheme, but the 68040 is a
  44. little more dynamic.  The 68040 has four cache lines for each index,
  45. so the 68040 cache can hold on to four different addresses that share
  46. the same index.  The 68040 also has a larger index (six bits).
  47.  
  48. While the caches are active, when the CPU executes an instruction
  49. that reads memory, it will check if that memory is already in the
  50. cache.  If the memory is in the cache and the cache entry (or, in the
  51. case of the 68040, the cache line) is marked as valid, a cache hit
  52. occurs, so the CPU reads from the cache instead of main memory.  If
  53. the memory is not in the cache, or the cache entry (or cache line) is
  54. marked invalid, a cache miss occurs, so the CPU has to perform a main
  55. memory fetch.
  56.  
  57. The cache lines are used in conjunction with the 68030's and 68040's
  58. burst mode.  Normally, the 68030 fills its caches one entry at a
  59. time.  While in burst mode, the CPU fills its caches a whole cache
  60. line at a time. This helps to reduce the number of cache misses.
  61.  
  62. On the 68030, it is possible to turn burst mode on and off
  63. independently of its caches.  If the 68030 cache is on and burst mode
  64. is off, the 68030 can fill its cache a single long word at a time,
  65. rather than the four words at a time it would do in burst mode.  The
  66. 68040 is different.  On the 68040, the only way to turn on burst mode
  67. is to turn on the cache, so there is no way to prevent a burst access
  68. when using the cache.  The 68040 always fills a whole cache line at a
  69. time.
  70.  
  71. The instruction cache on both CPUs is fairly straightforward.  As the
  72. CPU fetches instructions from memory, it copies them into the cache
  73. for quick access later.  The only time the CPU changes the
  74. instruction cache is when it does a memory fetch.
  75.  
  76. The data cache is different.  The data cache can change when the CPU
  77. fetches memory and when the CPU executes an instruction that writes
  78. to memory.  The 68030 and 68040 deal with this differently.
  79.  
  80. The 68030 data cache is a write-through cache.  This means whenever
  81. the 68030 executes an instruction that writes to memory, the 68030
  82. always performs a write to main memory, even if that address is in
  83. the data cache.
  84.  
  85. When a data write causes a cache miss, the 68030 will act as if it
  86. has no data cache and write directly to memory (except in
  87. write-allocate mode--see the next paragraph).  When a data write
  88. causes a cache hit, the 68030 will update the cache entry (or
  89. entries) as well as write to memory.  Basically, on a memory write
  90. operation, the 68030 will only update cache entries that are
  91. currently cached.  It will not allocate a new cache entry for a cache
  92. miss.
  93.  
  94. The 68030 data cache has a mode called write-allocate.  In this mode,
  95. the 68030 not only updates the data in the cache, but, in the case of
  96. a cache miss, the 68030 can also allocate a new cache entry.  While
  97. in this mode, if a data write causes a cache miss, the CPU first
  98. marks the corresponding cache entry as invalid (or, if in burst mode,
  99. the CPU marks the entire cache line as invalid).  If the data write
  100. is a long word write and it is aligned on a long word boundary, the
  101. CPU updates that long word in the cache and marks it as valid. The
  102. 68040 data cache is not always a write through cache.  It has a mode
  103. called copyback.  While in copyback mode, a write operation on the
  104. 68040 will not write through to memory.  The data will remain in the
  105. data cache until the CPU flushes it out.  For more information, see
  106. the article, ``68040 Compatibility Warning'' from the July/August
  107. 1991 Amiga Mail.
  108.  
  109.  
  110. Zorro III and the 68030
  111.  
  112. When the 68030 reads data from a memory address, it will cache that
  113. address only if that memory address is marked as cachable.  Certain
  114. areas of memory cannot be cachable, for example, hardware registers
  115. of a Zorro III card.  On the Zorro III bus, when the CPU attempts to
  116. read an address that is not cachable, the device that exists in that
  117. address space asserts the Zorro III cache inhibit line (/CINH).  The
  118. bus controller will turn this signal into the CPU's cache inhibit
  119. signal, which tells the CPU not to cache the address.
  120.  
  121. The problem is with the 68030's data cache in write-allocate mode
  122. (which the Amiga OS requires).  When write-allocate mode is disabled,
  123. the 68030 will only allocate a cache entry for a data address if the
  124. address is cachable.  The CPU knows if the address is cachable
  125. because the device told it using the cache inhibit line.
  126.  
  127. While in write-allocate mode, the 68030 will also allocate a cache
  128. entry during certain write operations.  If, while in write-allocate
  129. mode, the 68030 writes a long word to a long word aligned address,
  130. the 68030 will write to that address and will allocate a cache entry
  131. for that address.  This provides a loophole where the 68030 will
  132. allocate a cache entry for a non-cachable memory address.  If the CPU
  133. does a long word write to a Zorro III hardware register that happens
  134. to be aligned on a long word address, the 68030 will put that address
  135. in the cache.  If the CPU attempts to read from that address again
  136. and that address happens to still be in the data cache, it will see
  137. the value in the cache and will not attempt to read the hardware
  138. register.
  139.  
  140. So far, the conditions under which this loophole can occur have been
  141. rare.  The loophole requires that a hardware register be both
  142. writable and readable, aligned on a long word address, and be four
  143. bytes long. This precludes the Amiga custom chip registers as they
  144. are not both readable and writable (in general they are not four
  145. bytes long either).  Zorro II devices don't apply as Zorro II devices
  146. only have a 16 bit wide data path.  The small size of the 68030's
  147. data cache also makes it tough for a register write and read to occur
  148. without a cache flush happening in between.
  149.  
  150. However, as Zorro III devices start to hit the market, the conditions
  151. under which the loophole can occur will become more commonplace.  To
  152. avoid this problem, Zorro III card designers can utilize the
  153. following hardware trick.
  154.  
  155. The trick is to ``mirror'' all of the hardware registers.  In this
  156. scheme, every register that is both readable and writable is
  157. accessible at two addresses.  One address is exclusively for reading
  158. and the other address is exclusively for writing.  Now, if the 68030
  159. performs a write and allocates a cache entry, the 68030 caches the
  160. writing address, but not the reading address.
  161.  
  162. Another hardware trick that might seem to be a viable solution is to
  163. align 32-bit register ports so that they do not fall on a long word
  164. boundary.  Using this method, the 68030 will never cache the register
  165. address on a data write because it is not aligned properly.  The
  166. problem with this method is that reading (or writing) a long word
  167. from a non-long word aligned address is considerably slower than from
  168. a long word aligned address. This can almost double the amount of bus
  169. traffic, making the entire system slower.
  170.  
  171.  
  172. The 68040 and Zorro III
  173.  
  174. The 68040 does not have the problem that the 68030 has with Zorro II
  175. space.  The 68040 contains two registers to give data space a default
  176. mapping without the need of a Memory Management Unit (MMU).  On an
  177. Amiga with a 68040, Exec uses one of these registers to map the low
  178. 24-bits of the Amiga's address space (the Zorro II range,
  179. $00000000-$00FFFFFFFF) as non-cachable and serialized1 .
  180.  
  181. The Amiga uses the second register to map the remaining memory
  182. ($01000000-$FFFFFFFF) as cachable and non-serialized.  Because of its
  183. mapping, any RAM in this region will yield considerably higher
  184. performance than RAM in Zorro II space.  Unfortunately, this mapping
  185. can cause problems for a Zorro III device that is not RAM.
  186.  
  187. When the 68040 accesses a Zorro III device that is in cachable
  188. address space, the device can still tell the CPU that an address is
  189. not cachable by asserting the CPU's cache inhibit line.  This
  190. overrides the default mapping the 68040 has placed on the address
  191. space.  However, this does not stop the CPU from doing a full line
  192. burst.  When accessing address space mapped as cachable, the 68040
  193. will always attempt to read or write a block the size of an entire
  194. cache line (four long words).
  195.  
  196. This presents a problem when the 68040 attempts to read from a Zorro
  197. III device that is in cachable address space and the device asserts
  198. the CPU's cache inhibit line.  The 68040 cannot notice that the Zorro
  199. III device asserted the CPU's cache inhibit line until the 68040
  200. reads the first long word of the burst cycle.  By the time the 68040
  201. sees that the first long word is not cachable, it is already too late
  202. to stop the burst cycle, so the 68040 finishes the burst.  When the
  203. burst is done, the 68040 throws out the extra three long words from
  204. the burst read.  In this case, the 68040 performs four long word
  205. memory accesses instead of just one.
  206.  
  207. Writing to the device is even worse.  When the 68040 writes data to
  208. an address that is not currently in the data cache, the 68040 will
  209. first try to fill a cache line.  When the 68040 sees that the device
  210. asserts the CPU's cache inhibit line, it will finish the read and
  211. then write out one long word.  Essentially, to perform a single
  212. memory write, the 68040 performs four memory reads and one memory
  213. write.
  214.  
  215. These excessive memory accesses can significantly hinder system
  216. performance.  Certain Zorro III designs could make the 68040 as much
  217. as four to five times slower.
  218.  
  219. The full line bursts also cause a second potential problem for some
  220. possible Zorro III devices.  Reading certain types of hardware
  221. registers will trigger the hardware to perform some extra function as
  222. well.  It is not uncommon for a hardware device to supply a new data
  223. value for a register after the CPU reads that register. If a Zorro
  224. III device has such a register and the device is located in cachable
  225. address space, the device can experience problems with reads and
  226. writes of addresses surrounding the register.  If the CPU reads a
  227. second hardware register at an address that is in the same quad-long
  228. word as the register (i.e. the first register's address would be in
  229. the same cache line as the second register's address),   when the CPU
  230. performs its full line burst, it will read the first register in
  231. addition to the second register.  Because the CPU reads the first
  232. register, the device will reload the first register with a new value,
  233. losing the previous value.
  234.  
  235.  
  236. The Solution
  237.  
  238. There is a solution that will fix both potential problems for Zorro
  239. III cards on 68040-based Amigas.  The MMU in the 68040 can map
  240. specific pages of memory as non-cachable.  The 37.10 version of the
  241. 68040.library creates MMU tables that map only Zorro III memory
  242. devices as cachable (actually it maps all RAM except Chip RAM as
  243. cachable).  The library marks other Zorro III devices as
  244. non-cachable.  The new library prevents the 68040 from doing full
  245. line bursts to non-cachable devices, so the CPU only reads or writes
  246. one long word at a time.  As the 68040.library uses the MMU to map
  247. all address space, invalid addresses can no longer cause bus errors
  248. (Guru #00000002), which may help a few ill-behaved products to work
  249. on 68040 systems.
  250.  
  251. The 37.10 68040.library is part of the V39 OS present on the current
  252. A4000.  Developers who are working on or have released 68040-based
  253. expansion devices should contact CATS to obtain information on
  254. distributing the library with their product.
  255.  
  256. There is only one problem with this solution.  Not all 68040s have
  257. MMUs.  There are three kinds of 68040 chip: the MC68040, the
  258. MC68LC040, and the MC68EC040.  The MC68040 has both an Floating Point
  259. Unit (FPU) and an MMU.  The MC68LC040 is a regular MC68040 without an
  260. FPU.  The MC68EC040 is a MC68LC040 without an MMU.
  261.  
  262. As the 68040.library requires an MMU to map address space, the fix
  263. described above will not work on systems with an MC68EC040.  Because
  264. burst mode on the 68040 is activated along with the cache, there is
  265. no way to prevent a 68EC040-equipped Amiga from doing full line
  266. bursts when accessing cachable address space.  This means a 68EC040
  267. cannot prevent the excessive reads and writes when reading
  268. non-cachable Zorro III devices that reside in cachable address space.
  269. A 68EC040-equipped Amiga will experience a significant decrease in
  270. performance when accessing non-cachable Zorro III devices.  For this
  271. reason we cannot recommend that anyone use a 68EC040 (or any future
  272. 68000 series CPU that has no MMU) as the CPU on a Zorro III bus
  273. system.
  274.  
  275. If someone decides not to heed this warning and create a 68EC040 CPU
  276. card for the Zorro III bus, there is nothing the 68EC040 card can do
  277. to prevent these problems, although there is still a way for a Zorro
  278. III card to prevent the second 68040 problem (the ``register
  279. trigger'' problem).  A Zorro III card that needs to use ``trigger''
  280. registers can arrange the trigger registers so that each register is
  281. in its own quad-long word.  This way, when the 68EC040 reads one of
  282. these registers, the read operation won't disturb other registers, as
  283. two registers do not reside in the same quad-long word.  Note that
  284. this fix will not prevent the first problem (the performance decrease
  285. problem) and it does not address the possibility that future CPUs may
  286. have an eight or sixteen long word cache line.
  287.  
  288.